package cn.kgc.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: mosin
 * @version: v1.0  2022/5/5
 */
@Controller
@RequestMapping("cookie")
public class CookieController {

    @RequestMapping("ck1")
    public String test01(HttpServletResponse response){
        Cookie ck = new Cookie("msg", "cookieValue");
        ck.setPath("/");
        response.addCookie(ck);
        return "redirect:/static/cookie.jsp";
    }


    @RequestMapping("ck2")
    public String test02(@CookieValue("msg") String cookie){
        System.out.println("cookie = " + cookie);
        return "redirect:/static/cookie.jsp";
    }


}
